home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group97b.txt / 000066_icon-group-sender _Tue Sep 16 08:00:13 1997.msg < prev    next >
Internet Message Format  |  2000-09-20  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: from kingfisher.CS.Arizona.EDU (kingfisher.CS.Arizona.EDU [192.12.69.239])
  3.     by cheltenham.cs.arizona.edu (8.8.7/8.8.7) with SMTP id IAA07325
  4.     for <icon-group-addresses@cheltenham.CS.Arizona.EDU>; Tue, 16 Sep 1997 08:00:12 -0700 (MST)
  5. Received: by kingfisher.CS.Arizona.EDU (5.65v4.0/1.1.8.2/08Nov94-0446PM)
  6.     id AA01560; Tue, 16 Sep 1997 08:00:11 -0700
  7. To: icon-group@cs.arizona.edu
  8. Date: 16 Sep 1997 10:39:52 GMT
  9. From: espie@vishnu.jussieu.fr (Marc ESPIE)
  10. Message-Id: <5vlnlo$juv$1@vishnu.jussieu.fr>
  11. Organization: Universites Paris VI/Paris VII - France
  12. Sender: icon-group-request@cs.arizona.edu
  13. References: <Stuart.Robinson-1609971341100001@asianstmg-221.anu.edu.au>
  14. Subject: Re: case selection expression
  15. Errors-To: icon-group-errors@cs.arizona.edu
  16. Status: RO
  17.  
  18. Stuart Robinson (Stuart.Robinson@anu.edu.au) wrote:
  19. : How can I use the case selection expression to 1) check each line of a
  20. : text for the presence or absence of a few key words and 2) do something
  21. : according to which key word is present?  The logic is basically:
  22.  
  23. : do 1    if find    "x"
  24. : do    2    if find    "y"
  25. : do    3    if find    "z"
  26. : do 4 otherwise (as a default)
  27.  
  28. : I think that the case selection expression (i.e., case X of {}) would
  29. : work, but I don't really understand it and I don't have my manual handy. 
  30. : I know that this can be done with if-then (else), but what I want to know
  31. : is how "case of {}" works.
  32.  
  33. In your specific example, you need to combine generators with case.
  34. e.g.:
  35.  
  36. case (find( i <- "x"|"y"|"z"), i) of
  37. "x":  do 1
  38. "y":  do 2
  39. "z":  do 3
  40. default: do 4
  41.  
  42. but I am not really sure that it is clearer than a cascaded
  43. if find("x") then do 1
  44. else if find("y") then do 2
  45.  
  46. which is as readable once you've got the knack of it, and certainly
  47. more efficient in the present case under the current implementation of Icon.
  48.